import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:yp/Xwidgets/cache_image.dart';
import 'package:yp/config/config.dart';
import 'package:yp/pages/order_groupsettlement/view.dart';
import 'package:yp/pages/order_settlements/widgets/style.dart';
import 'package:yp/pages/order_settlements/widgets/text_input.dart';

// import 'package:yp/widgets/button_widget.dart';
import 'package:yp/Xwidgets/pay_bottom_sheet.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yp/pages/order_settlements/widgets/EsIconButton.dart';
import 'package:yp/router.dart';
import 'package:yp/utils/util.dart';
import 'logic.dart';
import 'state.dart';
import 'package:intl/intl.dart';
import 'package:yp/helper.dart';

typedef ClickCallback = void Function(int selectIndex, String selectString,
    {Map<String, dynamic> info});

class EndSaleOrderPage extends StatefulWidget {
  @override
  _EndSaleOrderPageStates createState() => _EndSaleOrderPageStates();
}

class _EndSaleOrderPageStates extends State<EndSaleOrderPage>
    with SingleTickerProviderStateMixin {
  final EndSaleOrderLogic logic = Get.put(EndSaleOrderLogic());
  final EndSaleOrderState state = Get.find<EndSaleOrderLogic>().state;

  @override
  void initState() {
    super.initState();
  }

  // Function setGift(index) {
  //   logic.clickGift(index);
  // }

  @override
  Widget build(
    BuildContext context,
  ) {
    return WillPopScope(
      onWillPop: () async {
        Get.back(result: true);
        return true;
      },
      child: Scaffold(
          appBar: AppBar(
            backgroundColor: Config.mainColor,
            brightness: Brightness.light,
            iconTheme: IconThemeData(color: Colors.white),
            title: Text(
              "结算",
              style: TextStyle(color: Colors.white, fontSize: 32.sp),
            ),
            centerTitle: true,
            elevation: 0,
          ),
          body: GetBuilder<EndSaleOrderLogic>(builder: (logic) {
            return state.total != null &&
                    state.total['order_items'] != null &&
                    state.total['order_items'].length != 0
                ? Column(
                    children: [
                      Expanded(
                        child: ListView(
                            shrinkWrap: true,
                            primary: true,
                            children: [
                              Column(
                                children: [
                                  /// 地址
                                  Container(
                                    padding: EdgeInsets.only(
                                        left: 30.w,
                                        right: 30.w,
                                        top: state.orderAddress != null &&
                                                state.orderAddress[
                                                        "cont_empe"] !=
                                                    null
                                            ? 20.w
                                            : 0),
                                    decoration: BoxDecoration(
                                      color: Colors.white,
                                    ),
                                    child: Column(
                                      children: [
                                        Column(children: [
                                          state.orderAddress != null &&
                                                  state.orderAddress[
                                                          "cont_empe"] !=
                                                      null
                                              ? GestureDetector(
                                                  onTap: () {
                                                    if (!state.isZiTi) {
                                                      Get.toNamed(
                                                          RouteConfig
                                                              .addressList,
                                                          arguments: {
                                                            "userNum":
                                                                state.userNum,
                                                            'adr_num_id': state
                                                                    .orderAddress[
                                                                'adr_num_id']
                                                          }).then((value) {
                                                        if (value != null &&
                                                            value["address"] !=
                                                                null) {
                                                          state.orderAddress =
                                                              value["address"];
                                                          logic.onReady();
                                                        }
                                                      });
                                                    } else {
                                                      toast("请关闭自提");
                                                    }
                                                  },
                                                  child: InkWell(
                                                      child: Row(
                                                    mainAxisAlignment:
                                                        MainAxisAlignment
                                                            .center,
                                                    crossAxisAlignment:
                                                        CrossAxisAlignment
                                                            .center,
                                                    children: [
                                                      Container(
                                                        width: 650.w,
                                                        child: Column(
                                                          mainAxisAlignment:
                                                              MainAxisAlignment
                                                                  .start,
                                                          crossAxisAlignment:
                                                              CrossAxisAlignment
                                                                  .start,
                                                          children: [
                                                            RichText(
                                                              text: TextSpan(
                                                                children: [
                                                                  TextSpan(
                                                                    text: state
                                                                        .orderAddress[
                                                                            "cont_empe"]
                                                                        .toString(),
                                                                    style: TextStyle(
                                                                        color: Colors
                                                                            .black,
                                                                        fontSize:
                                                                            28.w),
                                                                  ),
                                                                  WidgetSpan(
                                                                      child:
                                                                          SizedBox(
                                                                    width: 20.w,
                                                                  )),
                                                                  TextSpan(
                                                                    text: state
                                                                        .orderAddress[
                                                                            "contact_no"]
                                                                        .toString(),
                                                                    style: TextStyle(
                                                                        color: Colors
                                                                            .black,
                                                                        fontSize:
                                                                            28.sp),
                                                                  ),
                                                                  state.orderAddress[
                                                                              "default_sign"] ==
                                                                          1
                                                                      ? WidgetSpan(
                                                                          child: Container(
                                                                              margin: EdgeInsets.only(left: 10.w),
                                                                              padding: EdgeInsets.symmetric(horizontal: 5.w, vertical: 2.w),
                                                                              color: Config.mainColor,
                                                                              child: Text(
                                                                                "默认",
                                                                                style: TextStyle(
                                                                                  fontSize: 20.sp,
                                                                                  color: Colors.white,
                                                                                ),
                                                                              )),
                                                                        )
                                                                      : WidgetSpan(
                                                                          child:
                                                                              Container()),
                                                                ],
                                                              ),
                                                            ),
                                                            SizedBox(
                                                              height: 10.w,
                                                            ),
                                                            Text(
                                                              "${state.orderAddress["prv_name"]} ${state.orderAddress["city_name"]} ${state.orderAddress["city_area_name"]} ${state.orderAddress["town_name"] ?? ''} ${state.orderAddress["adr"]}",
                                                              style: TextStyle(
                                                                color: Colors
                                                                    .black,
                                                                fontSize: 26.sp,
                                                              ),
                                                              maxLines: 2,
                                                              textAlign:
                                                                  TextAlign
                                                                      .start,
                                                              overflow:
                                                                  TextOverflow
                                                                      .ellipsis,
                                                            ),
                                                            SizedBox(
                                                              height: 5.w,
                                                            ),

                                                          ],
                                                        ),
                                                      ),
                                                      SizedBox(
                                                        width: 5.w,
                                                      ),
                                                      Center(
                                                        child: Icon(
                                                          Icons
                                                              .arrow_forward_ios_rounded,
                                                          size: 15,
                                                          color:
                                                              Color(0xffB7B7B7),
                                                        ),
                                                      ),
                                                    ],
                                                  )),
                                                )
                                              : SizedBox(),

                                          state.orderAddress != null &&
                                                  state.orderAddress[
                                                          "cont_empe"] !=
                                                      null
                                              ? SizedBox(
                                                  height: 20.w,
                                                )
                                              : SizedBox(),
                                        ]),
                                      ],
                                    ),
                                  ),
                                  Container(
                                    height: 24.w,
                                  ),

                                  /// 商品部分
                                  Container(
                                    child: Column(
                                      children: [
                                        ListView.builder(
                                          itemBuilder: (ctx, index) {
                                            return Container(
                                                color: Colors.white,
                                                padding: EdgeInsets.only(
                                                    left: 20.w, right: 20.w),
                                                child: Column(
                                                  children: [
                                                    /// 店铺名
                                                    Container(
                                                      padding: EdgeInsets.only(
                                                          top: 20.w,
                                                          bottom: 20.w),
                                                      decoration: BoxDecoration(
                                                        border: Border(
                                                          bottom: BorderSide(
                                                            color: Color(
                                                                0xfff0f0f0),
                                                          ),
                                                        ),
                                                      ),
                                                      child: Row(
                                                        crossAxisAlignment:
                                                            CrossAxisAlignment
                                                                .center,
                                                        mainAxisAlignment:
                                                            MainAxisAlignment
                                                                .start,
                                                        children: [
                                                          Image(
                                                            image: AssetImage(
                                                                "assets/images/orderStore.png"),
                                                            width: 36.w,
                                                          ),
                                                          SizedBox(
                                                            width: 5.w,
                                                          ),
                                                          Text(
                                                            logic.state.goodsItem[
                                                                    index][
                                                                "ec_shop_name"],
                                                            style: TextStyle(
                                                                fontSize: 26.sp,
                                                                color: Color(
                                                                    0xff333333)),
                                                          ),
                                                        ],
                                                      ),
                                                    ),
                                                    Container(
                                                      color: Colors.white,
                                                      padding:
                                                          EdgeInsets.symmetric(
                                                              vertical: 34.w),
                                                      child: ListView(
                                                        shrinkWrap: true,
                                                        //添加子元素
                                                        children: logic
                                                            .state.goodsItem
                                                            .map<Widget>(
                                                                (item) {
                                                          return Row(
                                                            crossAxisAlignment:
                                                                CrossAxisAlignment
                                                                    .start,
                                                            children: [
                                                              Container(
                                                                  margin: EdgeInsets
                                                                      .only(
                                                                          right: 10
                                                                              .w),
                                                                  width: 96.w,
                                                                  height: 96.w,
                                                                  decoration:
                                                                      BoxDecoration(
                                                                    borderRadius:
                                                                        BorderRadius
                                                                            .all(
                                                                      Radius.circular(
                                                                          10.w),
                                                                    ),
                                                                    border:
                                                                        Border
                                                                            .all(
                                                                      color: Color(
                                                                          0xfff0f0f0),
                                                                    ),
                                                                  ),
                                                                  child:
                                                                      CachedImage(
                                                                    path: item[
                                                                        "item_picture"],
                                                                    width:
                                                                        160.w,
                                                                    height:
                                                                        160.w,
                                                                  )),
                                                              Expanded(
                                                                child: Column(
                                                                  crossAxisAlignment:
                                                                      CrossAxisAlignment
                                                                          .start,
                                                                  children: [
                                                                    Text(
                                                                        item[
                                                                            'item_name'],
                                                                        overflow:
                                                                            TextOverflow
                                                                                .ellipsis,
                                                                        style: TextStyle(
                                                                            fontSize:
                                                                                13)),
                                                                    SizedBox(
                                                                        height:
                                                                            4),
                                                                    Row(
                                                                      mainAxisAlignment:
                                                                          MainAxisAlignment
                                                                              .spaceBetween,
                                                                      children: [
                                                                        Row(
                                                                          children: [
                                                                            Text(
                                                                              '￥',
                                                                              style: TextStyle(color: EsColors.Primary, fontSize: 12),
                                                                            ),
                                                                            Text(
                                                                              toConstraintLen(item["trade_price"], 3),
                                                                              style: TextStyle(color: EsColors.Primary),
                                                                            ),
                                                                            Text(
                                                                              ' x${logic.state.goodsItem.length}',
                                                                              style: TextStyle(color: const Color(0xffcccccc)),
                                                                            ),
                                                                          ],
                                                                        ),
                                                                        state.dueTime !=
                                                                                ''
                                                                            ? Expanded(
                                                                                child: Container(
                                                                                  alignment: Alignment.centerRight,
                                                                                  child: Text(
                                                                                    '发货时间: ${state.dueTime}',
                                                                                    style: TextStyle(fontSize: 13),
                                                                                    overflow: TextOverflow.ellipsis,
                                                                                  ),
                                                                                ),
                                                                              )
                                                                            : SizedBox(),
                                                                      ],
                                                                    ),
                                                                  ],
                                                                ),
                                                              ),
                                                            ],
                                                          );
                                                        }).toList(),
                                                      ),
                                                    ),
                                                  ],
                                                ));
                                          },
                                          shrinkWrap: true,
                                          physics:
                                              NeverScrollableScrollPhysics(),
                                          itemCount:
                                              logic.state.goodsItem.length,
                                        ),
                                        Container(
                                          color: Colors.white,
                                          padding: EdgeInsets.only(
                                              left: 20.w,
                                              right: 20.w,
                                              bottom: 24.w),
                                          margin: EdgeInsets.only(bottom: 24.w),
                                          child: Row(
                                            children: [
                                              Container(
                                                margin: EdgeInsets.only(
                                                    right: 10.w),
                                                width: 96.w,
                                                height: 96.w,
                                              ),
                                              Expanded(
                                                child: Column(
                                                  crossAxisAlignment:
                                                      CrossAxisAlignment.start,
                                                  children: [
                                                    Text(
                                                      '预售价格￥${toConstraintLen(state.depositAmount + state.balanceAmount, 3)}, 付定金￥${toConstraintLen(state.depositAmount, 3)}, 尾款需要￥${toConstraintLen(state.balanceAmount, 3)}',
                                                      style: TextStyle(
                                                          color: const Color(
                                                              0xff666666),
                                                          fontSize: 12),
                                                    ),
                                                    Text(
                                                        '           (如有优惠券可在尾款使用)',
                                                        style: TextStyle(
                                                            color: const Color(
                                                                0xff666666),
                                                            fontSize: 12)),
                                                    SizedBox(height: 20),
                                                    Row(
                                                      mainAxisAlignment:
                                                          MainAxisAlignment
                                                              .spaceBetween,
                                                      children: [
                                                        Column(
                                                          children: [
                                                            Text(
                                                              '定金',
                                                              style: TextStyle(
                                                                  fontSize: 13),
                                                            ),
                                                            Container(
                                                                width: 1,
                                                                height: 25,
                                                                color: const Color(
                                                                    0xff333333)),
                                                            Text(
                                                              '尾款',
                                                              style: TextStyle(
                                                                fontSize: 13,
                                                                color: EsColors
                                                                    .Primary,
                                                              ),
                                                            ),
                                                          ],
                                                        ),
                                                        Column(
                                                          children: [
                                                            Text(
                                                              '￥${toConstraintLen(state.depositAmount, 3)}',
                                                              style: TextStyle(
                                                                  fontSize: 13),
                                                            ),
                                                            Container(
                                                                width: 1,
                                                                height: 25),
                                                            Text(
                                                              '￥${toConstraintLen(state.balanceAmount, 3)}',
                                                              style: TextStyle(
                                                                  color: EsColors
                                                                      .Primary,
                                                                  fontSize: 13),
                                                            ),
                                                          ],
                                                        ),
                                                      ],
                                                    ),
                                                  ],
                                                ),
                                              ),
                                            ],
                                          ),
                                        ),
                                      ],
                                    ),
                                  ),
                                  Column(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    children: [
                                      /// 配送类型
                                      TextInputWidget(
                                        title: "配送类型",
                                        suffixWidget: Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.end,
                                          children: [
                                            Text(
                                              '快递',
                                              style: TextStyle(
                                                fontSize: 28.sp,
                                                color: Color(0xff333333),
                                              ),
                                            ),
                                          ],
                                        ),
                                      ),

                                      // 优惠券
                                      TextInputWidget(
                                        title: "优惠券",
                                        suffixWidget: InkWell(
                                          onTap: () {
                                            selectProduct(context);
                                            // if (state.couponList.length > 0) {
                                            //   selectProduct(context);
                                            // } else {
                                            //   toast('暂无可用优惠券');
                                            // }
                                          },
                                          child: Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.end,
                                            children: [
                                              ConstrainedBox(
                                                constraints: BoxConstraints(
                                                  maxWidth: 450.w,
                                                ),
                                                child: Text(
                                                  state.couponList.length > 0 &&
                                                          state.couponData !=
                                                              null &&
                                                          state.couponData[
                                                                  'show_status'] ==
                                                              3
                                                      ? '去选择'
                                                      : state.couponList
                                                                      .length >
                                                                  0 &&
                                                              state.couponData !=
                                                                  null &&
                                                              state.couponData[
                                                                      'show_status'] ==
                                                                  1
                                                          ? '-${state.couponsPayAmount}'
                                                          : '暂无可用优惠券',
                                                  style: TextStyle(
                                                    fontSize: 28.sp,
                                                    color: Color(0xffcccccc),
                                                  ),
                                                  maxLines: 1,
                                                  overflow:
                                                      TextOverflow.ellipsis,
                                                ),
                                              ),
                                              Icon(
                                                Icons.arrow_forward_ios_rounded,
                                                color: Color(0xffcccccc),
                                                size: 14,
                                              )
                                            ],
                                          ),
                                        ),
                                      ),

                                      if (state.showJiFen)
                                        Container(
                                          padding: EdgeInsets.symmetric(
                                            vertical: 20.w,
                                            horizontal: 20.w,
                                          ),
                                          color: Colors.white,
                                          child: Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.spaceBetween,
                                            crossAxisAlignment:
                                                CrossAxisAlignment.center,
                                            children: [
                                              Column(
                                                crossAxisAlignment:
                                                    CrossAxisAlignment.start,
                                                children: [
                                                  Text(
                                                    state.isJiFen
                                                        ? "使用${state.validPoint}积分抵扣￥${Utils.toConstraintLen(state.deductPoint, 3)}"
                                                        : state.validPoint > 0
                                                            ? "是否使用积分支付"
                                                            : "您暂时无可用积分",
                                                    style: TextStyle(
                                                      color: Color(0xff666666),
                                                      fontSize: 28.sp,
                                                    ),
                                                  ),
                                                  SizedBox(
                                                    height: 10.w,
                                                  ),
                                                  Text(
                                                    "使用积分抵扣无法使用福利卡",
                                                    style: TextStyle(
                                                      color: Colors.grey[400],
                                                      fontSize: 19.sp,
                                                    ),
                                                  ),
                                                ],
                                              ),
                                              Container(
                                                  width: 240.w,
                                                  height: 60.w,
                                                  child: FittedBox(
                                                    fit: BoxFit.scaleDown,
                                                    alignment:
                                                        Alignment.centerRight,
                                                    child: CupertinoSwitch(
                                                      value: state.isJiFen,
                                                      activeColor:
                                                          Config.mainColor,
                                                      onChanged: (v) {
                                                        // logic.selectSwitch();
                                                        logic.selectSwitch1();
                                                      },
                                                    ),
                                                  )),
                                            ],
                                          ),
                                        ),
                                    ],
                                  ),

                                  /// 结算金额优惠详情
                                  Container(height: 24.w),
                                ],
                              )
                            ]),
                      ),
                      Container(
                        color: Colors.white,
                        width: 750.w,
                        height: 100.w,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                SizedBox(
                                  width: 10.w,
                                ),
                                Text(
                                  '￥${toConstraintLen(state.needPayAmount, 3)}',
                                  // '￥${toConstraintLen(state.balanceAmount, 3)}',
                                  style: TextStyle(
                                      color: Config.mainColor, fontSize: 32.w),
                                ),
                              ],
                            ),
                            SizedBox(
                              width: 10.w,
                            ),
                            GestureDetector(
                              onTap: () {
                                // print(state.isJiFen);
                                // print(state.total["need_pay_amount"]);
                                // print(state.GiftcardList);
                                // print(state.cardType);
                                // print(state.GiftcardList.length);
                                // return;
                                // 积分
                                if (state.isJiFen) {
                                  logic.orderSubmit(context);
                                  return;
                                } else {
                                  // 现金
                                  if (state.GiftcardList.length <= 0 ||
                                      state.cardType == 1 ||
                                      state.couponList.length > 0 &&
                                          state.couponData != null &&
                                          state.couponData['show_status'] ==
                                              1) {
                                    logic.orderSubmit(context);
                                    return;
                                  }
                                  // 购物卡
                                  payBottomSheet.showPay(context, state,
                                      logic.orderSubmit, logic.clickGift);
                                }
                              },
                              child: state.isLoading
                                  ? Container(
                                      color: const Color(0xffcccccc),
                                      height: 100.w,
                                      width: 340.w,
                                      child: Center(
                                        child: Text(
                                          "尾款支付中",
                                          style: TextStyle(
                                            color: Colors.white,
                                            fontSize: 36.sp,
                                          ),
                                        ),
                                      ),
                                    )
                                  : Container(
                                      color: Config.mainColor,
                                      height: 100.w,
                                      width: 340.w,
                                      child: Center(
                                        child: Text(
                                          "确认付尾款",
                                          style: TextStyle(
                                            color: Colors.white,
                                            fontSize: 36.sp,
                                          ),
                                        ),
                                      ),
                                    ),
                            )
                          ],
                        ),
                      ),
                    ],
                  )
                : Container();
          })),
    );
  }


  void selectProduct(BuildContext context) {
    //用于在底部打开弹框的效果
    showModalBottomSheet(
        isScrollControlled: true,
        backgroundColor: Colors.white,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(10.0.w),
        ),
        builder: (BuildContext context) {
          //构建弹框中的内容
          return Container(
              height: 1000.w, width: 750.w, child: FSActiveCouponItem());
        },
        context: context);
  }


}

///支付
showPayWay(BuildContext context, ClickCallback clickCallback, state, loice) {
  int index = 0;
}

class FSActiveCouponItem extends StatefulWidget {
  FSActiveCouponItem({Key key}) : super(key: key);

  @override
  _FSActiveCouponItemState createState() {
    return _FSActiveCouponItemState();
  }
}

class _FSActiveCouponItemState extends State<FSActiveCouponItem>
    with SingleTickerProviderStateMixin {
  TabController tabControllers;

  @override
  void initState() {
    tabControllers = TabController(length: 2, vsync: this);
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Column(children: [
      TabBar(controller: tabControllers, labelColor: Colors.black, tabs: [
        Tab(text: '可用优惠券'),
        Tab(text: '不可用优惠券'),
      ]),
      Expanded(
        child: TabBarView(
            controller: tabControllers,
            children: [FSAvailableRoll(), FSnoavailableRollState()]),
      )
    ]);
  }
}

class FSAvailableRoll extends StatefulWidget {
  FSAvailableRoll({Key key}) : super(key: key);

  @override
  FSAvailableRollState createState() => FSAvailableRollState();
}

class FSAvailableRollState extends State<FSAvailableRoll> {
  final EndSaleOrderLogic logic = Get.put(EndSaleOrderLogic());
  final EndSaleOrderState state = Get.find<EndSaleOrderLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        GetBuilder<EndSaleOrderLogic>(builder: (logic) {
          return Expanded(
            child: Container(
              padding: EdgeInsets.symmetric(vertical: 20.w),
              margin: EdgeInsets.only(right: 22.w, left: 22.w),
              decoration: BoxDecoration(
                color: Colors.white,
                border: Border(
                  bottom: BorderSide(
                    color: Color(0xfff0f0f0),
                  ),
                ),
              ),
              child: SingleChildScrollView(
                child: GetBuilder<EndSaleOrderLogic>(builder: (logic) {
                  return ListView.builder(
                    itemBuilder: (ctx, index) {
                      var item = state.couponList[index];
                      // print('优惠券: $item');
                      return InkWell(
                        onTap: () {
                          Navigator.pop(context);
                          logic.selectCoupon(index, item);
                        },
                        child: Container(
                          width: 718.w,
                          height: 208.w,
                          margin: EdgeInsets.symmetric(vertical: 10.w),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.all(
                              Radius.circular(16.w),
                            ),
                            image: DecorationImage(
                              image: AssetImage("assets/images/couponbg.png"),
                              fit: BoxFit.cover,
                            ),
                            boxShadow: [
                              BoxShadow(
                                color: Color(0xFF6498F1).withOpacity(.14),
                                offset: Offset(0, 0), //阴影y轴偏移量
                                blurRadius: 1,
                                spreadRadius: .3,
                              )
                            ],
                          ),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Container(
                                width: 200.w,
                                padding: EdgeInsets.only(top: 50.w),
                                child: Column(
                                  children: [
                                    RichText(
                                      text: TextSpan(
                                        children: [
                                          TextSpan(
                                            text: '￥',
                                            style: TextStyle(
                                              color: Color(0xffC99F4F),
                                              fontSize: 28.w,
                                            ),
                                          ),
                                          TextSpan(
                                            text: item['qmz'].toString(),
                                            style: TextStyle(
                                              color: Color(0xffC99F4F),
                                              fontSize: 50.w,
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                    Text(
                                      item['least_cost'] == 0
                                          ? "无门槛"
                                          : "满${item['least_cost'].toString()}元可用",
                                      style: TextStyle(
                                        color: Color(0xffC99F4F),
                                        fontSize: 22.w,
                                      ),
                                    )
                                  ],
                                ),
                              ),
                              SizedBox(width: 10.w),
                              Container(
                                width: 310.w,
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    Text(
                                      item['qname'].toString(),
                                      style: TextStyle(
                                        color: Color(0xff000000),
                                        fontSize: 28.sp,
                                      ),
                                      maxLines: 1,
                                    ),
                                    SizedBox(height: 60.w),
                                    Text(
                                      "${item['sdate'].split(" ")[0]}-${item['edate'].split(" ")[0]}",
                                      style: TextStyle(
                                        color: Color(0xff999999),
                                        fontSize: 24.sp,
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                              SizedBox(width: 20.w),
                              Container(
                                padding: EdgeInsets.only(right: 10.w),
                                child: Image.asset(
                                  item['show_status'] == 1
                                      ? "assets/images/select2.png"
                                      : "assets/images/select1.png",
                                  width: 35.w,
                                ),
                              )
                            ],
                          ),
                        ),
                      );
                    },
                    itemCount: state.couponList.length,
                    shrinkWrap: true,
                    physics: NeverScrollableScrollPhysics(),
                  );
                }),
              ),
            ),
          );
        }),
      ],
    );
  }
}

class FSnoavailableRollState extends StatefulWidget {
  FSnoavailableRollState({Key key}) : super(key: key);

  @override
  _FSnoavailableRollStateState createState() => _FSnoavailableRollStateState();
}

class _FSnoavailableRollStateState extends State<FSnoavailableRollState> {
  final EndSaleOrderLogic logic = Get.put(EndSaleOrderLogic());
  final EndSaleOrderState state = Get.find<EndSaleOrderLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Expanded(
          child: Container(
            padding: EdgeInsets.symmetric(vertical: 20.w),
            margin: EdgeInsets.only(right: 22.w, left: 22.w),
            decoration: BoxDecoration(
              color: Colors.white,
              border: Border(
                bottom: BorderSide(
                  color: Color(0xfff0f0f0),
                ),
              ),
            ),
            child: SingleChildScrollView(
              child: GetBuilder<EndSaleOrderLogic>(builder: (logic) {
                return ListView.builder(
                  itemBuilder: (ctx, index) {
                    var item = state.nocouponList[index];
                    return Container(
                      width: 718.w,
                      height: 208.w,
                      margin: EdgeInsets.symmetric(vertical: 10.w),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.all(
                          Radius.circular(16.w),
                        ),
                        image: DecorationImage(
                          image: AssetImage("assets/images/couponbg.png"),
                          fit: BoxFit.cover,
                        ),
                        boxShadow: [
                          BoxShadow(
                            color: Color(0xFF6498F1).withOpacity(.14),
                            offset: Offset(0, 0), //阴影y轴偏移量
                            blurRadius: 1,
                            spreadRadius: .3,
                          )
                        ],
                      ),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          Container(
                            width: 200.w,
                            padding: EdgeInsets.only(top: 50.w),
                            child: Column(
                              children: [
                                RichText(
                                  text: TextSpan(
                                    children: [
                                      TextSpan(
                                        text: '￥',
                                        style: TextStyle(
                                          color: Color(0xffC99F4F),
                                          fontSize: 28.w,
                                        ),
                                      ),
                                      TextSpan(
                                        text: item['qmz'].toString(),
                                        style: TextStyle(
                                          color: Color(0xffC99F4F),
                                          fontSize: 50.w,
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                                Text(
                                  "满${item['least_cost'].toString()}元可用",
                                  style: TextStyle(
                                    color: Color(0xffC99F4F),
                                    fontSize: 22.w,
                                  ),
                                )
                              ],
                            ),
                          ),
                          SizedBox(width: 30.w),
                          Container(
                            width: 310.w,
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text(
                                  item['qname'].toString(),
                                  style: TextStyle(
                                    color: Color(0xff000000),
                                    fontSize: 28.sp,
                                  ),
                                  maxLines: 1,
                                ),
                                SizedBox(height: 60.w),
                                Text(
                                  "${item['sdate'].split(" ")[0]}-${item['edate'].split(" ")[0]}",
                                  style: TextStyle(
                                    color: Color(0xff999999),
                                    fontSize: 24.sp,
                                  ),
                                ),
                                // SizedBox(height: 20.w),
                                // Text(
                                //   "剩余990张",
                                //   style: TextStyle(
                                //     color: Color(0xff666666),
                                //     fontSize: 24.sp,
                                //   ),
                                // ),
                              ],
                            ),
                          ),
                        ],
                      ),
                    );
                  },
                  itemCount: state.nocouponList.length,
                  shrinkWrap: true,
                  physics: NeverScrollableScrollPhysics(),
                );
              }),
            ),
          ),
        ),
      ],
    );
  }
}
